<template>
	<div>
		<!-- 审批弹窗 -->
    <el-dialog 
      title="审批"
      append-to-body
      :visible.sync="approveDialog"
      :close-on-click-modal="false" 
      :before-close="closeApproveDialog"
      width="60%"
      class="related_party_plan_approve_dialog"
    >
      <avue-form 
        ref="approveForm" 
        v-model="approveObj" 
        :option="approveOption" 
        @submit="confirmApproveRelatedParty"
      >
        <template slot="menuForm">
          <el-button 
            size="small"
            icon="el-icon-close"
            @click="closeApproveDialog()">
            取 消
          </el-button>
        </template>
      </avue-form>
    </el-dialog>
	</div>
</template>

<script>
import {approveRelatedParty } from "@/api/equipmentmanage/threeSimultaneousne";

export default {
  props: {
    approveDialog: {default: false},
    approveForm: {default: ""}
  },
  data() {
    return {
      approveObj: {}
    }
  },
  watch: {
    approveDialog(){
      if(this.approveDialog === true){
        this.initData();
      }
    }
  },
  computed: {
    approveOption() {
      return {
        size: "small",
        submitText: "审 批",
        mockBtn: false,
        printBtn: false,
        emptyBtn: false,
        column: [
          {
            label: "项目名称",
            prop: "xmmc",
            search: true,
            disabled:true,
            align: "center",
          },
          {
            label: "项目编号",
            prop: "xmbh",
            disabled:true,
            hide: true,
          },
          {
            label: "项目性质",
            align: "center",
            prop: "xmxz",
            disabled:true,
            hide: true,
          },
          {
            label: "安全设施三同时",
            align: "center",
            disabled:true,
            prop: "aqsssts",
            hide: true,
          },
          {
            label: "项目开工日期",
            prop: "xmkgrq",
            align: "center",
            disabled:true,
            hide: true,
            type: "date",
            format: "yyyy-MM-dd",
            valueFormat: "yyyy-MM-dd"
          },
          {
            label: "项目竣工验收日期",
            prop: "xmjgrq",
            align: "center",
            disabled:true,
            hide: true,
            type: "date",
            format: "yyyy-MM-dd",
            valueFormat: "yyyy-MM-dd"
          },
          {
            label: "项目描述",
            prop: "xmms",
            align: "center",
            disabled:true,
            type: "textarea",
            span: 24,
            maxlength: 150,
          },
           {
            label: "批准部门",
            prop: "pzbm",
            disabled:true,
            align: "center",
            display: false,
            width: 300,
            slot: true
          },
          {
            label: "批准日期",
            prop: "pzrq",
            disabled:true,
            align: "center",
            type: "date",
            format: "yyyy-MM-dd",
            valueFormat: "yyyy-MM-dd"
          },
          {
            label: "建设日期",
            prop: "jsrq",
            align: "center",
            disabled:true,
            hide: true,
            type: "date",
            format: "yyyy-MM-dd",
            valueFormat: "yyyy-MM-dd"
          },
          {
            label: "完成日期",
            prop: "wcrq",
            disabled:true,
            hide: true,
            align: "center",
            type: "date",
            format: "yyyy-MM-dd",
            valueFormat: "yyyy-MM-dd"
          },
          {
            label: "备注：",
            prop: "bz",
            hide: true,
            disabled: true,
            type: "textarea",
            span: 24,
            maxlength: 150
          },
          {
            label: "项目建设单位",
            prop: "xmjsdw",
            disabled:true,
            hide: true,
          },
          {
            label: "项目总投资(万元)",
            prop: "xmztz",
            hide: true,
            disabled:true,
          },
          {
            label: "项目建设地点",
            prop: "xmjsdd",
            disabled:true,
            hide: true,
          },
          {
            label: "项目进展情况",
            prop: "xmjz",
            hide: true,
            disabled:true,
          },
          {
            label: "审批状态",
            prop: "zt",
            align: "center",
            display: false,
            slot: true,
            disabled:true,
          },
          {
            label: "审批",
            prop: "approve",
            align: "center",
            width: 220,
            slot: true,
            display: false,
            disabled:true,
          },
          {
            label: "是否通过",
            prop: "passed",
            span: 24,
            type: "radio",
            dicData: [{
              label: "通过",
              value: 1
            }, {
              label: "不通过",
              value: 0
            }],
            rules: [{
              required: true,
              message: "请选择是否通过",
              trigger: "change"
            }]
          },
          {
            label: "审批意见",
            prop: "spyj",
            type: "textarea",
            span: 24,
            maxlength: 150,
          }
        ]
      }
    }
  },
  mounted() {
    this.initData();
  },
  methods: {
    // 初始化数据
    initData() {
      this.approveObj = this.formatApproveObj(this.approveForm);
    },
    // 详情
    // getRelatedPartyPlanDetail() {
    //   getDetail(this.approvePartyId).then(res => {
    //     var resData = res.data.data;
        
    //   });
    // },

    // 获取审批弹窗数据
    formatApproveObj(row) {
      var data = {};
      for(var key in row) {
        data[key] = row[key];
      }
      data["passed"] = "";
      data["spyj"] = "";
      return data;
    },

    // 关闭、取消审批弹窗
    closeApproveDialog() {
      this.$emit('closeApproveDialog');
    },
    // 确认审批
    confirmApproveRelatedParty() {
      this.$refs.approveForm.validate((vaild,done)=>{
        if(vaild){
          approveRelatedParty(this.approveObj.id, this.approveObj.passed, this.approveObj.spyj).then(res => {
            if(res.data.success) {
              this.$emit('confirmApproveRelatedParty');
            }
          });
          done();
        }
      })
    }

  }
}
</script>

<style lang="scss" scoped>
.approve_setting_footer {
  text-align: center;
  margin-top: 15px;

  .el-button {
    width: 100px;
    height: 35px;
  }
}
</style>